package com.billow.control
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.StageQuality;
	import flash.geom.Matrix;

	public class BitmapControl
	{
		public function BitmapControl()
		{
			
		}
		
		
		/**
		 * 获取指定大小位图 
		 * @param display
		 * @param wid
		 * @param hig
		 * @param quality
		 * @param transparent
		 * @param fillColor
		 * @return 
		 * 
		 */		
		public function getBitmapSize(display:DisplayObject ,wid:Number ,hig:Number ,quality:String=null , transparent:Boolean=true, fillColor:uint=4.294967295E9):BitmapData
		{
			var a:Number = wid/display.width;//display.width>=wid?wid/display.width:display.width/wid;
			var d:Number = hig/display.height;//display.height>=hig?hig/display.height:display.height/hig;
			var bd:BitmapData = new BitmapData(wid ,hig ,transparent ,fillColor);
			var mt:Matrix = new Matrix(a ,0 ,0 ,d ,0 ,0);
			//bd.drawWithQuality(display ,mt ,null ,null ,null ,false ,quality);
			bd.draw(display ,mt ,null ,null ,null ,false);
			return bd;
		}
		
		
		/**
		 * 获取 指定最大高宽 等比例位图 
		 * @param display
		 * @param maxWid
		 * @param maxHig
		 * @param quality
		 * @param transparent
		 * @param fillColor
		 * @return 
		 * 
		 */		
		public function getBitmapScale(display:DisplayObject ,maxWid:Number ,maxHig:Number ,quality:String=null , transparent:Boolean=true, fillColor:uint=4.294967295E9):BitmapData
		{
			var wid:Number;
			var hig:Number;
			
			if(display.width>maxWid || display.height>maxHig)
			{
				if(display.width>=display.height)
				{
					wid = maxWid/display.width*display.width;
					hig = maxWid/display.width*display.height;
				}else{
					wid = maxHig/display.height*display.width;
					hig = maxHig/display.height*display.height;
				}
			}else{
				wid = display.width;
				hig = display.height;
			}
			
			return getBitmapSize(display ,wid ,hig ,quality ,transparent ,fillColor);
		}
	}
}